#!/bin/bash
PATH=$PATH":$PWD"
export PATH

#Set the parameters
#outputPath=Crill/ExpOut/Earthquake

outputPath=ExpOut/Earthquake

dataset=/home/panitee/Dataset/Earthquake1976To2002/EarthquakeFullTrim.csv
dataspec=/home/panitee/Dataset/Earthquake1976To2002/Earthquake1.xml

Num_Threads=(6 12 24 48)  # a list of OPM_NUM_THREADS to be run
num_Examples=330561 # only needed when DoubleArrayDataset is used
InterestingnessFunction=VarianceHigh
k=100
p=50	#p should be larger than 48 in Crill if task parallelism is used.
q=12
rEta=2
rthreshold=1.2
rbeta=1.4
clusterIDIndex=1  #specify the index of meta data for the cluster ID
Num_Runs_different_seeds=1 # set the number of runs of experiments of this setting, the seed of each run will be different,
                           # if multiruns of the same seed is desired, set this attribute to 1 and increase number of i in the for loop in the experiment script

maxRuntime=0              # set the maximum time (secs) allowed to run CLEVER, 0 for no restriction
maxIteration=0            # set the maximum number of iterations for CLEVER, 0 for no restriction
distanceMatrix=0
useDoubleArrayDataset=0   # always set to 0 for now, so motiple copies of the data set will not be created when task parallelism is used
useLoopPara=1            # 1: data parallelism(loop parallelism), 0: task parallelism
incrementalUpdate=0  ###  incremental update only works when useLoopPara is set to 1 

#end of parameter setting
##----------------------
# Environment Setting
   if [ -d $outputPath ]
    then
        echo "$outputPath already exist \n"
    else
        echo "Mkdir $outputPath \n"
        mkdir -p $outputPath
   fi

##-----------------------
##Run Experiments
#-------------------------

for j in ${Num_Threads[@]} 
do
	export OMP_NUM_THREADS=$j
	echo "Threads: $j"
	for i in 1 2 3
	do
   	  if [ -d $outputPath/Exp${i} ]	
  	   then
     	     echo "ExpOut/Earthquake/Exp${i} already exist"
  	   else
     	     echo "Create directory ExpOut/Earthquake/Exp${i} "
	     mkdir $outputPath/Exp${i}
  	   fi

	  if [ -d ${outputPath}/Exp${i}/p${p}q${q}K${k}LoopPara${useLoopPara} ]
            then
              echo "Clustering results and representatives will be stored at "${outputPath}/Exp${i}/p${p}q${q}K${k}LoopPara${useLoopPara}" \n"
            else
              mkdir ${outputPath}/Exp${i}/p${p}q${q}K${k}LoopPara${useLoopPara};
          fi
	
	  echo "experiment : $i"
	  ./Debug/CLEVER_C++ $dataset $dataspec $InterestingnessFunction $p $q $rEta $rthreshold $rbeta $distanceMatrix $clusterIDIndex $Num_Runs_different_seeds $useDoubleArrayDataset $num_Examples $k $useLoopPara $maxRuntime $maxIteration $incrementalUpdate > ${outputPath}/p${p}q${q}K${k}LoopPara${useLoopPara}_exp${i}_OMP${j}.out
	
          echo "./Debug/CLEVER_C++ $dataset $dataspec $InterestingnessFunction $p $q $rEta $rthreshold $rbeta $distanceMatrix $clusterIDIndex $Num_Runs_different_seeds $useDoubleArrayDataset $num_Examples $k $useLoopPara $maxRuntime $maxIteration $incrementalUpdate"
	  mv ${dataset}_OMP_${j}_Results*.csv ${outputPath}/Exp${i}/p${p}q${q}K${k}LoopPara${useLoopPara}/
	done
done
